﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WeiXinWeb.Models;
using System.Data;
using System.Text;
using WeiXinWeb.Services;


namespace WeiXinWeb.Server
{
    public class Import_info : PSIBaseService
    {
        /// <summary>
        /// 得到所有的进口货物明细
        /// </summary>
        /// <returns></returns>
        public List<InConsignationDetail> GetimportList()
        {
            List<InConsignationDetail> result = new List<InConsignationDetail>();
            var sql = new StringBuilder("select * from tms_in_consignation_detail");
            Query(sql.ToString(),ready =>
            {
                var item = new InConsignationDetail
                {
                   Id=ready.GetString(ready.GetOrdinal("id")),
                   ParentId = ready.GetString(ready.GetOrdinal("parent_id")),
                   Address = ready.GetString(ready.GetOrdinal("f_address")),
                   CntType = ready.GetString(ready.GetOrdinal("f_cnt_type")),
                   CntNumber1 = ready.GetString(ready.GetOrdinal("f_cnt_num_1")),
                   PlanDt = ready.GetDateTime(ready.GetOrdinal("f_plan_act_dt")),
                   Status=ready.GetString(ready.GetOrdinal("f_status")),
                   isweixin = (IsWXStatus)Enum.Parse(typeof(IsWXStatus), ready.GetInt32(ready.GetOrdinal("i_isweixin")).ToString())
                };
                result.Add(item);
            });
            return result;     
        }


        
        /// <summary>
        /// 根据条件选择一条实体
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public InConsignationDetail GetimportSinlg(InConsignationDetail model)
        {
            var result=new InConsignationDetail();
            var sql = new StringBuilder("select * from tms_in_consignation_detail where 1=1");
            var p = CreateDbParameters();
            if (!String.IsNullOrEmpty(model.Id))
            {
                sql.Append(" and id=@id");
                p.AddWithValue("id", model.Id);
            }
            Query(sql.ToString(), p, ready =>
            {
               result= new InConsignationDetail
                {
                    Id = ready.GetString(ready.GetOrdinal("id")),
                    ParentId = ready.GetString(ready.GetOrdinal("parent_id")),
                    BlNumber = ready.GetString(ready.GetOrdinal("f_bl_number")),
                    CntType = ready.GetString(ready.GetOrdinal("f_cnt_type")),
                    CntNumber = ready.GetString(ready.GetOrdinal("f_cnt_num")),
                    Address = ready.GetString(ready.GetOrdinal("f_address")),
                    GoodsOwner = ready.GetString(ready.GetOrdinal("f_goods_owner")),
                    GoodsOwnerTel = ready.GetString(ready.GetOrdinal("f_goods_owner_tel")),
                    Memo = ready.GetString(ready.GetOrdinal("f_memo")),
                    CntOwner = ready.GetString(ready.GetOrdinal("f_cnt_owner")),
                    UnloadMan = ready.GetString(ready.GetOrdinal("f_unload_man")),
                    UnloadManTel = ready.GetString(ready.GetOrdinal("f_unload_man_tel")),
                    Goods = ready.GetString(ready.GetOrdinal("f_goods")),
                    Status = ready.GetString(ready.GetOrdinal("f_status")),
                    isweixin=(IsWXStatus)Enum.Parse(typeof(IsWXStatus), ready.GetInt32(ready.GetOrdinal("i_isweixin")).ToString())
                };
            });
            return result;
        }
    }
}